from pydantic import BaseModel, EmailStr, Field
from typing import Optional, List, Any

# 用户相关
class UserCreate(BaseModel):
    username: str
    email: EmailStr
    password: str
    user_type: str
    department: Optional[str] = "general"

class UserOut(BaseModel):
    id: int
    username: str
    email: EmailStr
    user_type: str
    department: str
    status: str

class UserUpdate(BaseModel):
    email: Optional[EmailStr]
    user_type: Optional[str]
    department: Optional[str]

class UserStatusUpdate(BaseModel):
    status: str

class UserLogin(BaseModel):
    username: str
    password: str

class TokenOut(BaseModel):
    access_token: str
    refresh_token: str
    token_type: str = "bearer"

class PasswordResetRequest(BaseModel):
    email: EmailStr

class PasswordChange(BaseModel):
    old_password: str
    new_password: str

class TokenRefreshRequest(BaseModel):
    refresh_token: str

# 角色相关
class RoleCreate(BaseModel):
    role_name: str
    description: Optional[str]

class RoleOut(BaseModel):
    id: int
    role_name: str
    description: Optional[str]

class RoleUpdate(BaseModel):
    role_name: Optional[str]
    description: Optional[str]

# 权限相关
class PermissionCreate(BaseModel):
    resource: str
    action: str
    attribute_condition: Optional[Any]

class PermissionOut(BaseModel):
    id: int
    resource: str
    action: str
    attribute_condition: Optional[Any]

class PermissionUpdate(BaseModel):
    resource: Optional[str]
    action: Optional[str]
    attribute_condition: Optional[Any]

# 分页通用
class PageMeta(BaseModel):
    total: int
    page: int
    page_size: int

class PageResult(BaseModel):
    meta: PageMeta
    items: list 